package me.zhujin.java.learnjava.myserver.servlet;

import me.zhujin.java.learnjava.myserver.MyRequest;
import me.zhujin.java.learnjava.myserver.MyResponse;
import me.zhujin.java.learnjava.myserver.MyServlet;
import me.zhujin.java.learnjava.myserver.util.ScriptUtil;

import java.io.FileNotFoundException;

/**
 * Created by zhujin on 10/24/16.
 * blog:www.zhujin.me
 * email: zhujin.nova@gmail.com
 */
public class ScriptMspServlet extends MyServlet {

    @Override
    protected void doPost(MyRequest request, MyResponse response) throws Exception {
        doGet(request, response);
    }

    @Override
    protected void doGet(MyRequest request, MyResponse response) throws Exception {
        String url = request.getUrl();
//        if (url.endsWith("msp")||url.endsWith(".jsp")) {//js 脚本
        try {

            Object res = ScriptUtil.getScriptHttpBody(url, request.getParamsList().toArray());
            if (res == null) {
                flush404(response);
                return;
            }
            response.printLn(res.toString());
        } catch (FileNotFoundException e) {
            flush404(response);
        }
//        }
//        String name = request.getParmer("name");
//        String password = request.getParmer("password");
//        if (name == null) {
//            flushBody(response, "-名字为空-");
//            return;
//        }
//        if (password == null) {
//            flushBody(response, "-密码为空-");
//            return;
//        }
//        if (name.equals("zhujin.me") && password.equals("zhujin.me")) {
//            flushBody(response, "欢迎-" + name + "Login-Servlet");
//        } else {
//            flushBody(response, "用户名.密码错误");
//        }


    }


}
